// 分类模块
import { findHeadCategory } from '@/api/cate'
import { category } from '@/utils/constant'
export default {
  namespaced: true,
  state () {
    return {
      list: category.map((item, index) => ({ id: index, name: item }))
    }
  },
  mutations: {
    initList (state, payload) {
      state.list = payload
    }
  },
  actions: {
    async loadCateList (context) {
      const ret = await findHeadCategory()
      if (ret.result) {
        context.commit('initList', ret.result)
      }
    }
  },
  getters: {
    leftCates (state) {
      return state.list.map((item) => {
        return {
          ...item,
          children: item.children && item.children.filter((item, index) => index < 2)
        }
      })
    }
  }
}
